<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>添加咨询</title>
    <?php PrintPageHead(); ?>
    <link href="../resource/css/hermes.css" rel="stylesheet">
    <link href="../resource/js/calendar/calendar-blue.css" type="text/css" rel="stylesheet">
    <script src="../resource/js/calendar/calendar.js" type="text/javascript"></script>
    <script src="../resource/js/hermes.js"></script>
    <?php
    if (!array_key_exists("公众号ID",$_SESSION)) {
        header("Location:back.php");
    }
    pdo()->beginTransaction();
    $bm=new C后台管理员();
    $添加咨询 = 'back.php?state=back13Add_ZiXun';
    $id=$_GET['id'];
    if($id){
        $图文=pdo()->selectAll("select * from 咨询详情 WHERE 咨询id=".$id);
    }
    ?>
</head>
<body>


<div class="container-fluid">
    <?php include_once 'back_header.php'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title">图文消息</h3></div>
        <div class="panel-group"  id="accordion" role="tablist" aria-multiselectable="true">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row" >
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            排序
                        </div>
                        <div class="col-xs-3 col-sm-3" style="text-align:center">
                            标题
                        </div>
                        <div class="col-xs-2 col-sm-2" style="text-align:center">
                            图片预览
                        </div>
                        <div class="col-xs-2 col-sm-2" style="text-align:center">
                           描述
                        </div>
                        <div class="col-xs-2 col-sm-2" style="text-align:center">
                            添加时间
                        </div>
                        <div class="col-xs-2 col-sm-2" style="text-align:center" >
                            操作
                        </div>
                    </div>
                </div>
            </div>
            <?php foreach($图文 as $v){?>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row" >
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['排序']?>&nbsp;
                            </div>
                            <div class="col-xs-3 col-sm-3">
                                <a href="<?=$v['文章url']?>" target="_blank"><?=$v['标题']?></a>
                            </div>
                            <div class="col-xs-2 col-sm-2">
                                <img src="<?=$v['图片url']?>" style="width:200px;" />
                            </div>
                            <div class="col-xs-2 col-sm-2">
                                <?=$v['description']?>
                            </div>
                            <div class="col-xs-2 col-sm-2">
                                <?=$v['添加时间']?>
                            </div>
                            <div class="col-xs-2 col-sm-2" style="text-align:center">

                                <button onclick="bianji('<?=$v['id']?>')" class=" btn btn-primary">编辑</button>&nbsp;
                                <button onclick="shanchu('<?=$v['id']?>')" class=" btn btn-primary">删除</button>&nbsp;
                            </div>
                        </div>
                    </div>
                </div>
                <?php  }?>
        </div>
        <div style="padding: 30px 30px 10px;" >
            <div class="panel-heading text-center"><h3 class="panel-title">添加图文消息</h3></div>
            <form class="bs-example bs-example-form" role="form" id="form1" enctype="multipart/form-data">
                <div class="input-group">
                    <span class="input-group-addon">标题</span>
                    <input type="text" class="form-control" name="标题">
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon">图片url</span>
                    <input type="file"  name="图片url" >
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon">文章url</span>
                    <input type="text" class="form-control" name="文章url">
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon">描述</span>
                    <input type="text" class="form-control" name="description">
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon">排序</span>
                    <input type="text" class="form-control" name="排序">
                </div>
                <br>
                <div class="input-group">
                    <input type="button" onclick="fun()" class="form-control btn btn-primary" value="提交">
                </div>
            </form>

        </div>
    </div>
</div>

<div style="position: fixed;left:100px;top:100px;width:80%;height: 70%; background: #ccc;display: none;z-index: 3" id="xianshi">
    <div style="padding: 30px 30px 10px;" >
        <form class="bs-example bs-example-form" role="form" id="form2" enctype="multipart/form-data">
            <div class="input-group">
                <span class="input-group-addon">标题</span>
                <input type="text" class="form-control" name="标题">
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">修改图片url</span>
                <input type="file"  name="图片" >
                <input type="hidden"  name="图片url" >
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">原图片url</span>
                <input type="text" class="form-control" name="url" disabled >
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">文章url</span>
                <input type="text" class="form-control" name="文章url">
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">描述</span>
                <input type="text" class="form-control" name="description">
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">排序</span>
                <input type="text" class="form-control" name="排序">
                <input type="hidden" name="id">
            </div>
            <br>
            <input type="button" onclick="funxiugai()" class="btn btn-primary" value="提交">
            <input type="button" onclick="quxiao()" class=" btn btn-primary" value="取消">
            </div>
        </form>
    </div>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script src="../resource/js/jquery-form.js"></script>
<script language="JavaScript">

    $(function(){
        $(".fun").click(function(){
            $(this).next("div").show();
        })
        $(".fun1").click(function(){
            $(this).parent("div").hide();
        })
    });
    function fun(){
        url="BackSellerAjax.php?businessFlag=图文信息&id=<?=$id?>";
        $('#form1').ajaxSubmit({
            type:'post',
            url:url,
            success:function(msg) {
                alert(msg);
               location.reload();
            }
        })
    }
    function funxiugai(){
        $('#form2').ajaxSubmit({
            type:'post',
            url:"BackSellerAjax.php?businessFlag=修改图文信息",
            success:function(msg) {
                alert(msg);
                location.reload();
            }
        })
    }
    function bianji(zixun){
        $.post('BackSellerAjax.php',{'id':zixun,'businessFlag':'查看咨询'},function(data){
            var obj = eval('(' + data + ')');
            $("#xianshi").show();
            $("#form2").find("input[name='标题']").val(obj['标题']);
            $("#form2").find("input[name='图片url']").val(obj['图片url']);
            $("#form2").find("input[name='url']").val(obj['图片url']);
            $("#form2").find("input[name='文章url']").val(obj['文章url']);
            $("#form2").find("input[name='description']").val(obj['description']);
            $("#form2").find("input[name='排序']").val(obj['排序']);
            $("#form2").find("input[name='id']").val(obj['id']);

        });
    }

    function quxiao(){
        $("#xianshi").hide();
    }
    function shanchu(obj){
        $.post('BackSellerAjax.php',{'id':obj,'businessFlag':'删除图文消息'},function(data){
            alert("删除成功");
            location.reload();
        });
    }

</script>
</body>
</html>